package kr.hkit.powerjava.chapter12.work;
//comparaTo를 implements를 해야 정렬을 할 수 있음!!!!!
import java.util.Arrays;
import java.util.Comparator;

public class PersonTest {
	public static void main(String[] args) {
		Person[] arr = new Person[3];
		arr[0] = new Person("이태희", 180);
		arr[1] = new Person("이민정", 190);
		arr[2] = new Person("태연", 160);
		
		System.out.println("가장 키가 큰 사람은 " + getMaximum(arr));

		
		
		
		Arrays.sort(arr);
		prnArr(arr);
		
		int a = Arrays.binarySearch(arr, new Person("이민정"));
		System.out.println(a>0? "Found" + arr[a]: "Not Found"); 
		
		/*Person p = new Person("김태희");
		System.out.println(arr[0].equals(p));*/

		
	}	
		
		
	/*	System.out.println(arr[0].hashCode() + " " + p.hashCode());
		//해시코드 달라서 false나옴
*/		

		
	

	private static void prnArr(Person[] arr) {
		for (Person p : arr) {
			System.out.println(p);
		}
	}

	public static String getMaximum(Person[] array) {
		Comparator<Person> hSort = new Comparator<Person>() {
			@Override
			public int compare(Person o1, Person o2) {
				return o1.getHeight() - o2.getHeight();
			}
		}; 
	
		Arrays.sort(array,hSort);
//		prnArr(array);
		
		return array[array.length-1].getName();
	}
}

